import box/condit

Has-Android-PkgName(){
    [ -z "$1" ] && return 1
    local PM_LIST=($(pm list packages --user 0 2>&1 </dev/null | grep -E '^package:' | cut -d: -f2 -))
    local PM_INDEX=${#PM_LIST[@]}
    if ! ((PM_INDEX));then
        return 1
    else
        for i in ${PM_LIST[@]};do
            local name="$1"
            if In-Value i == name;then
                return 0
            fi
        done
        return 1
    fi
}

Remove-Android-Package(){
    [ -z "$1" ] && return 1
    if Has-Android-PkgName "$1";then
        am start \
           -a android.intent.action.DELETE \
           -d package:"$1" &>/dev/null
    else
        return 2
    fi
}

Install-Android-Package(){
    [ -z "$1" ] && return 1
    [ -f "$1" ] || return 2
    if Has-Android-PkgName "$1";then
        am broadcast --user 0 \
           -a android.intent.action.VIEW \
           -n com.termux/com.termux.app.TermuxOpenReceiver \
           -d "$1" &>/dev/null
    else
        return 2
    fi
}